<?php

class Application_Form_FormRegister extends Zend_Form
{

    public function init()
    {
        /* Form Elements & Other Definitions Here ... */
        $this->setName('register');
        $this->setMethod('post');
        $this->setAction('/account/register');
        $this->setAttrib('class', 'mod-register');
        $this->setDecorators(array('FormElements','Form'));
		
		/* Shared optios */
		$isEmpty = array(
			'messages' => array(
				'isEmpty' => 'my localized err msg')
		);
		
		$nombre = new Zend_Form_Element_Text('nombre');
        $nombre->setLabel('Nombre:');
        $nombre->setAttrib('placeholder', 'Usuario');
        $nombre->setAttrib('size', 30);
        // $nombre->removeDecorator('label');
        $nombre->removeDecorator('DtDdWrapper');
        $nombre->removeDecorator('htmlTag');
        //Validate
        $nombre->setRequired(true);
        // $nombre->addValidator('Alpha');
        // $nombre->addValidator('NotEmpty', true, $isEmpty);
		$nombre->addErrorMessage('Ingrese nombre y apellido');
		
		$email = new Zend_Form_Element_Text('email');
        $email->setLabel('E-mail:');
        $email->setAttrib('placeholder', 'E-mail');
        $email->setAttrib('size', 30);
        // $email->removeDecorator('label');
        $email->removeDecorator('DtDdWrapper');
        $email->removeDecorator('htmlTag');
        //Validate
        $email->setRequired(true);
        $email->addValidator('EmailAddress', true, array(
			'messages' => array(
				Zend_Validate_EmailAddress::INVALID => 'El email ingresado no es valido',
				Zend_Validate_EmailAddress::INVALID_FORMAT => 'El email ingresado no es valido',
				Zend_Validate_EmailAddress::INVALID_HOSTNAME => 'El email ingresado no es valido',
				Zend_Validate_EmailAddress::INVALID_MX_RECORD => 'El email ingresado no es valido',
				Zend_Validate_EmailAddress::INVALID_SEGMENT => 'El email ingresado no es valido',
				Zend_Validate_EmailAddress::DOT_ATOM => 'El email ingresado no es valido',
				Zend_Validate_EmailAddress::QUOTED_STRING => 'El email ingresado no es valido',
				Zend_Validate_EmailAddress::INVALID_LOCAL_PART => 'El email ingresado no es valido'
			)
		));
        $email->addValidator('Db_NoRecordExists', true,
			array('table' => 'accounts', 'field' => 'email', 'messages' => array(
				'recordFound' => 'Ese e-mail ya esta registrado')));
		$email->addValidator('NotEmpty');
		// $email->addValidator('NotEmpty', true, array(
			// 'messages' => array(
				// Zend_Validate_NotEmpty::IS_EMPTY => 'Ingrese un E-mail valido'
			// )
		// ));
		// $email->addErrorMessage('Ingrese un E-mail valido');
		
		$pswd = new Zend_Form_Element_Password('pwd');
        $pswd->setLabel('Password:');
        $pswd->setAttrib('placeholder', 'Password');
        $pswd->setAttrib('size', 30);
        // $pswd->removeDecorator('label');
        $pswd->removeDecorator('DtDdWrapper');
        $pswd->removeDecorator('htmlTag');
        //Validate
        $pswd->setRequired(true);
        $pswd->addFilter(new Zend_Filter_StringTrim());
        $pswd->addValidator('StringLength', false, array(6,15));
        $pswd->addErrorMessage('Por favor elija un password de entre 6 y 15 caracteres');
		
		$pswd2 = new Zend_Form_Element_Password('pwd-confirm');
		$pswd2->setLabel('Confirma:');
		$pswd2->setAttrib('placeholder', 'Password');
		$pswd2->setAttrib('size', 30);
		// $pswd2->removeDecorator('label');
        $pswd2->removeDecorator('DtDdWrapper');
        $pswd2->removeDecorator('htmlTag');
		//Validate
		$pswd2->setRequired(true);
        //$pswd2->addValidator('StringLength', false, array(6,15));
        //$pswd2->addValidator(new Zend_Validate_Identical($_POST['pwd']));//undefined index
        $pswd2->addValidator(new Zend_Validate_Identical('pwd'));
		$pswd2->addErrorMessage('Los passwords no coinciden');

		$cpos = new Zend_Form_Element_Text('codPostal');
        $cpos->setLabel('Codigo Postal:');
        $cpos->setAttrib('placeholder', 'Cod. Postal');
        $cpos->setAttrib('size', 30);
        // $cpos->removeDecorator('label');
        $cpos->removeDecorator('DtDdWrapper');
        $cpos->removeDecorator('htmlTag');
        //Validate
        $cpos->setRequired(true);
        $cpos->addValidator('Digits');
		$cpos->addErrorMessage('Ingrese el Codigo Postal');
		
		$submit = new Zend_Form_Element_Submit('signup');
        $submit->setLabel('Registrarse');
        $submit->setAttrib('class', 'btn');
        $submit->removeDecorator('DtDdWrapper');
        $submit->removeDecorator('htmlTag');
        //add to the form
        $this->addElements(array($nombre, $email, $pswd, $pswd2, $cpos, $submit));

    }


}

